<?php
namespace Client\Table;

use Zend\Db\Sql\Select;
use Zend\Paginator\Adapter\DbSelect;

use Zend\Paginator\Paginator;
use Zend\Db\Sql\Where;
use Zend\Db\ResultSet\ResultSet;

class CatalogTable extends CommonTable
{
    protected $table = 'hy_catalog';
    protected $id = 'catalog_id';

    
    /**
     * 返回所有清单
     */
    public function getAll(){
    	$select = new Select();
    	$select ->from($this->getTable())
    	->columns(array('catalog_id', 'catalog_name'))
    	->order('catalog_id DESC');
    	$rowset = $this->selectWith($select);
    	$result = $rowset->toArray();
    	return $result;
    }
    
    public function find($limit = 0, $paginated = false) {

        $select = new Select();
        $select ->from($this->getTable())
        ->columns(array('catalog_id', 'catalog_name'))
        ->order('catalog_id DESC');
        $rowset = $this->selectWith($select);
        $result = $rowset->toArray();
        return $result;
    }
    
    public function findOne($cate_id = 1) {
    
        
    }
    
    public function findByCateId($cate_id = 0, $limit = 10, $keyword = '', $paginated = false) {
        $select = new Select(array('c' => 'hy_catalog'));
        $select->columns(array('catalog_id'));
        $select->join(
            array('o' => 'hy_organization'),
            'o.catalog_id=c.catalog_id',
            array('org_id', 'org_name', 'org_thumb_image'),
            $select::JOIN_LEFT
            );
        
        if(!empty($keyword)) {
            $select->where(array('o.org_name' => $keyword));
        }
        
        if($cate_id) {
            $select->where(array('c.catalog_id' => $cate_id));
        }
        $select->order('o.org_level ASC');
        $select->limit($limit);
        $rowset = $this->selectWith($select);
        $result = $rowset->toArray();
        return $result;


    }

   

    





 
}